#start_info.py
#coding=utf-8
import requests
import socket
import MySQLdb
import uuid

def get_host_ip():
    try:
       s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
       s.connect(('8.8.8.8',80))
       ipmsg = socket.gethostname()+':'+s.getsockname()[0]
    finally:
       s.close()
    return ipmsg

def sendmsg(startmsg,imgurl):
     r=requests.get("http://www.163.com")
     if r.ok == True:
        ipmsg=get_host_ip()
        bearychat_msg={"text":startmsg+":" +ipmsg,"attachments":imgurl}
        bearychat_url = "https://hook.bearychat.com/=bwCqN/incoming/nUk7CqrMcy1Hk3IL4bhEs8SjwRCm4nTEFT+gNJoGAgU="
        requests.post(bearychat_url,json=bearychat_msg,params='payload')

if __name__ == '__main__':
     startmsg = "服务器已启动"
     imgurl = [{"images":[{"url":"http://image.techweb.com.cn/upload/2011/0617/img20110613083010640.jpg"}]}]
     sendmsg(startmsg,imgurl)
